package com.sz.wu.controller;

import com.sz.wu.model.PageBean;
import com.sz.wu.model.User;
import com.sz.wu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 显示所有成员
     */


    @RequestMapping("/showAll")
    @ResponseBody
    public PageBean<User> showAll(int pageNum, int pageSize) {
        System.out.println(pageNum);
        System.out.println(pageSize);
        PageBean<User> pageBean = userService.showAll(pageNum, pageSize);
        return pageBean;
    }


    @RequestMapping("/like")
    @ResponseBody
    public PageBean<User> Like(int pageNum, int pageSize, String like1) {
        if ("undefined".equals(like1)) {
            like1 = "";
        }
        PageBean<User> like = userService.Like(pageNum, pageSize, like1);
        return like;
    }


    @RequestMapping("delete")
    @ResponseBody
    public PageBean<User> delete(int id) {
        System.out.println(id);
        userService.delete(id);
        PageBean<User> like = userService.Like(123432, 5435435, null);
        return like;
    }


    //    修改成员
    @RequestMapping("update")
    @ResponseBody
    public PageBean<User> update(User user) {
        userService.update(user);
        PageBean<User> like = userService.Like(3543543, 553454353, null);
        return like;
    }


    @GetMapping("/showAll2")
    @ResponseBody
    public List<User> showAll2() {
        System.out.println("来了吗");
        return userService.showAll2();
    }
}
